package com.cssl.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cssl.mapper.BasicOperationalMapper;
import com.cssl.mapper.BasicOperationdetailsMapper;
import com.cssl.pojo.BasicOperational;
import com.cssl.pojo.BasicOperatonaldetails;
import com.cssl.pojo.vo.BasicBomdetailsVo;
import com.cssl.pojo.vo.BasicOperationdetailsVo;
import com.cssl.service.BasicOperationalService;
import com.cssl.service.BasicOperatonaldetailsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Service
public class BasicOperatonaldetailsServiceImpl extends ServiceImpl<BasicOperationdetailsMapper, BasicOperatonaldetails> implements BasicOperatonaldetailsService {
    @Resource
    private BasicOperationdetailsMapper basicOperationdetailsMapper;
    @Override
    public int deleteBasicOperationdetailsById(Long operational_id) {
        return basicOperationdetailsMapper.deleteBasicOperationdetailsById(operational_id);
    }

    @Override
    public int deleteBatchBasicOperationdetails(List<Long> operationalIds) {
        return basicOperationdetailsMapper.deleteBatchBasicOperationdetails(operationalIds);
    }

    @Override
    public List<BasicOperatonaldetails> getBasicOperationdetailsByOperationalId(Long operational_id) {
        return basicOperationdetailsMapper.getBasicOperationdetailsByOperationalId(operational_id);
    }

    @Override
    public List<BasicOperationdetailsVo> getBasicOperationdetailsByOperationalId2(Long operational_id) {
        return basicOperationdetailsMapper.getBasicOperationdetailsByOperationalId2(operational_id);
    }

    @Override
    public List<BasicOperatonaldetails> getBasicOperationdetailsByOperationalId3(Long operational_id) {
        return basicOperationdetailsMapper.getBasicOperationdetailsByOperationalId3(operational_id);
    }

    @Override
    public int delBatchBasicOperationdetails(List<Long> operationalIds) {
        return basicOperationdetailsMapper.delBatchBasicOperationdetails(operationalIds);
    }

    @Override
    public List<BasicOperationdetailsVo> getBasicOperationdetailsByOperationalId4(Long operational_id) {
        return basicOperationdetailsMapper.getBasicOperationdetailsByOperationalId4(operational_id);
    }

    @Override
    public List<BasicOperationdetailsVo> getBasicOperationdetailsByOperationalId5(Long operational_id) {
        List<BasicOperationdetailsVo> list =basicOperationdetailsMapper.getBasicOperationdetailsByOperationalId5(operational_id);
        System.out.println("dehfh："+list);
        // 使用 LinkedHashMap 去重，保留第一条
        Map<String, BasicOperationdetailsVo> map = new LinkedHashMap<>();
        for (BasicOperationdetailsVo vo : list) {
            String key = vo.getProduct_id().toString(); // 根据 productId 去重
            if (!map.containsKey(key)) {
                map.put(key, vo);
            }
        }

        List<BasicOperationdetailsVo> result = new ArrayList<>(map.values());
        return result;
    }
}
